package com.smartkey.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;

import com.smartkey.activity.HeadsetPluSelectorActivity;

public class HeadsetPlugReceiver extends BroadcastReceiver {

	// private static final String TAG = "HeadsetPlugReceiver";

	@Override
	public void onReceive(Context context, Intent intent) {

		if (intent.hasExtra("state")) {
			if (intent.getIntExtra("state", 0) == 0) {
				/*
				 * Toast.makeText(context, "headset not connected",
				 * Toast.LENGTH_LONG).show();
				 */
				context.sendBroadcast(new Intent(
						HeadsetPluSelectorActivity.ACTION_MSG));
			} else if (intent.getIntExtra("state", 0) == 1) {
				/*
				 * Toast.makeText(context, "headset connected",
				 * Toast.LENGTH_LONG) .show();
				 */
				Intent intentHeadsetPlug = new Intent(context,
						HeadsetPluSelectorActivity.class);
				intentHeadsetPlug.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(intentHeadsetPlug);
			}
		}
	}

}
